package com.lizhivscaomei.dueros.tobaccoguider.schedule;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lizhivscaomei.dueros.tobaccoguider.mapper.DetailMapper;
import com.lizhivscaomei.dueros.tobaccoguider.mapper.es.DetailRepository;
import com.lizhivscaomei.dueros.tobaccoguider.mapper.IntroduceMapper;
import com.lizhivscaomei.dueros.tobaccoguider.mapper.es.IntroduceRepository;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Slf4j
@Component
@AllArgsConstructor
public class EsAsynSchedule {
    private DetailRepository detailRepository;
    private IntroduceRepository introduceRepository;
    private DetailMapper detailMapper;
    private IntroduceMapper introduceMapper;
    private RestHighLevelClient esClent;

   /* @Scheduled(cron = "0/5 * * * * ? ")
    public void mysqlToEs() {
        this.asynDetail();
        this.asynIntroduce();
    }*/

    @Async
    public void asynDetail() {
        this.detailRepository.saveAll(this.detailMapper.selectList(new LambdaQueryWrapper<>()));
        log.info("基本信息全量同步完成");
    }

    @Async
    public void asynIntroduce() {
        this.introduceRepository.saveAll(this.introduceMapper.selectList(new LambdaQueryWrapper<>()));
        log.info("简介信息全量同步完成");
    }
}
